package com.arthur.budget;

import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;

public class Settings extends PreferenceActivity {
    EditTextPreference totalBalanceInput;
    
    BudgetManager bm;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        
        bm = BudgetManager.getInstance(this);
        
        totalBalanceInput = (EditTextPreference) findPreference("balanceTotal");
        totalBalanceInput.setText(String.valueOf(bm.getTotal()));
        totalBalanceInput.setSummary("Current total balance: [" + bm.getTotal() + "]");
        totalBalanceInput.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                bm.setTotal(Float.parseFloat((String) newValue));
                totalBalanceInput.setSummary("Current total balance: [" + bm.getTotal() + "]");
                return false;
            }
        });
    }
}
